<?php

/**
 * This is the model class for table "DiemHK2".
 *
 * The followings are the available columns in table 'DiemHK2':
 * @property integer $idDHK2
 * @property string $MaQT
 * @property string $MaMH
 * @property integer $D1923
 * @property integer $D2427
 * @property double $GK2
 * @property integer $D2831
 * @property integer $D3235
 * @property double $CK2
 * @property double $HLM2
 *
 * The followings are the available model relations:
 * @property MonHoc $maMH
 * @property QuaTrinh $maQT
 */
class DiemHK2 extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return DiemHK2 the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'DiemHK2';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('MaQT, MaMH', 'required'),
			array('D1923, D2427, D2831, D3235', 'numerical', 'integerOnly'=>true),
			array('GK2, CK2, HLM2', 'numerical'),
			array('MaQT, MaMH', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idDHK2, MaQT, MaMH, D1923, D2427, GK2, D2831, D3235, CK2, HLM2', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'maMH0' => array(self::BELONGS_TO, 'MonHoc', 'MaMH'),
			'maQT0' => array(self::BELONGS_TO, 'QuaTrinh', 'MaQT'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idDHK2' => 'id',
			'MaQT' => 'MaQT',
			'MaMH' => 'MaMH',
			'D1923' => '1923',
			'D2427' => '2427',
			'GK2' => 'GK2',
			'D2831' => '2831',
			'D3235' => '3235',
			'CK2' => 'CK2',
			'HLM2' => 'HLM2',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idDHK2',$this->idDHK2);
		$criteria->compare('MaQT',$this->MaQT,true);
		$criteria->compare('MaMH',$this->MaMH,true);
		$criteria->compare('D1923',$this->D1923);
		$criteria->compare('D2427',$this->D2427);
		$criteria->compare('GK2',$this->GK2);
		$criteria->compare('D2831',$this->D2831);
		$criteria->compare('D3235',$this->D3235);
		$criteria->compare('CK2',$this->CK2);
		$criteria->compare('HLM2',$this->HLM2);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
        
        public function getTenNH()
        {
            $modelQT = QuaTrinh::model()->findByPk($this->MaQT);
            $modelNH = NamHoc::model()->findByPk($modelQT["MaNH"]);
            return $modelNH["TenNH"];
        }
}